package lian_xi;

import javax.swing.*;
import java.util.concurrent.TimeUnit;


//多线程数据同步
public class YootkDemo {
            public static int money = 0;
            public static void main(String[] args) throws Exception{
                int[] data = new int[] {100, 200, 300};
                for (int x=0;x< data.length;x++){
                    final int temp = x;
                    new Thread(()->{
                        try{
                            TimeUnit.MILLISECONDS.sleep(100);
                        }catch (InterruptedException e){
                            money += data[temp];
                        }
                    }).start();
                }
                TimeUnit.SECONDS.sleep(1);
                System.out.println("【计算完成】最终存款总额："+money);
            }
}
